home *** CD-ROM | disk | FTP | other *** search
/ An Introduction to Progr…l Basic 6.0 (4th Edition) / An Introduction to Programming using Visual Basic 6.0.iso / COMMON / TOOLS / VB / CABINETS / MSDAO350.CAB / icontrols / RichText / AnsiBuffer.class (.txt) next >
Encoding:
Java Class File  |  1998-01-08  |  1.5 KB  |  49 lines

  1. package icontrols.RichText;
  2.  
  3. import com.ms.dll.DllLib;
  4.  
  5. class AnsiBuffer extends CharBuffer {
  6.    byte[] buffer;
  7.    int offset;
  8.  
  9.    int allocCoTaskMem() {
  10.       int result = DllLib.allocCoTaskMem(this.buffer.length);
  11.       DllLib.copy(this.buffer, 0, result, this.buffer.length);
  12.       return result;
  13.    }
  14.  
  15.    void putCoTaskMem(int ptr) {
  16.       DllLib.copy(ptr, this.buffer, 0, this.buffer.length);
  17.       this.offset = 0;
  18.    }
  19.  
  20.    AnsiBuffer(int size) {
  21.       this.buffer = new byte[size];
  22.    }
  23.  
  24.    String getString() {
  25.       int i;
  26.       for(i = this.offset; i < this.buffer.length && this.buffer[i] != 0; ++i) {
  27.       }
  28.  
  29.       String result = new String(this.buffer, this.offset, i - this.offset);
  30.       if (i < this.buffer.length) {
  31.          ++i;
  32.       }
  33.  
  34.       this.offset = i;
  35.       return result;
  36.    }
  37.  
  38.    void putString(String s) {
  39.       byte[] bytes = s.getBytes();
  40.       int count = Math.min(bytes.length, this.buffer.length - this.offset);
  41.       System.arraycopy(bytes, 0, this.buffer, this.offset, count);
  42.       this.offset += count;
  43.       if (this.offset < this.buffer.length) {
  44.          this.buffer[this.offset++] = 0;
  45.       }
  46.  
  47.    }
  48. }
  49.